//
//  NewpageTableViewCell.m
//  SunXi
//
//  Created by dllo on 15/12/5.
//  Copyright © 2015年 大远. All rights reserved.
//

#import "NewpageTableViewCell.h"

@interface NewpageTableViewCell ()
@property(nonatomic, strong) UILabel *time;
@property(nonatomic, strong) UILabel *user;
@property(nonatomic, strong) UILabel *mess;

@end

@implementation NewpageTableViewCell{
    UIImageView *_myimageView;
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self create];
    }
    return self;
}
- (void)create{
    _time = [[UILabel alloc]init];
    [SCV addSubview:_time];
    
    
    _user = [[UILabel alloc]init];
    [SCV addSubview:_user];
    
    _mess = [[UILabel alloc]init];
    [SCV addSubview:_mess];
    
    _myimageView = [[UIImageView alloc]init];
    [SCV addSubview:_myimageView];
    
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _time.frame = CGRectMake(0, 0, CWIDTH, 15);
    _time.textColor = BUTTONCOLOR;
    _time.font = [UIFont systemFontOfSize:13];
    _time.textAlignment = NSTextAlignmentCenter;
    
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone timeZoneWithName:@"shanghai"];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"MM-dd HH:mm"];
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:[self.model.time doubleValue] / 1000];
    NSString * dateString = [formatter stringFromDate:date];
    _time.text = dateString;
    
    _user.frame = CGRectMake(5, 20, CWIDTH - 10, 15);
    if ([self.model.type isEqualToNumber:@1]) {
        _user.textAlignment = 0;
        _user.text = self.model.user;
        _myimageView.frame = CGRectMake(CWIDTH / 3 * 2, 50, 30, 30);
        _mess.frame = CGRectMake(5, 40, CWIDTH / 3 * 2, 30);
        _mess.textAlignment = 0;

    }else{
        _user.textAlignment = 2;
        _user.text = [UserModel shareSingleton].userName;
        _myimageView.frame = CGRectMake(CWIDTH / 3 - 40, 50, 30, 30);
        _mess.frame = CGRectMake(CWIDTH / 3 - 5, 40, CWIDTH / 3 * 2, 45);
        _mess.textAlignment = 2;

    }
    
    _user.textColor = [UIColor colorWithRed:0.246 green:0.250 blue:0.255 alpha:1.000];
    _user.font = [UIFont systemFontOfSize:13];
   
    if ([self.model.mess hasPrefix:@"SXmovie:"]) {
        _myimageView.image = [UIImage imageNamed:@"shipin"];
        NSString *str = [self.model.mess stringByReplacingOccurrencesOfString:@"SXmovie:" withString:@"分享:"];
        NSArray *strArr = [str componentsSeparatedByString:@"网址"];
        _mess.text = [strArr firstObject];
    }else if ([self.model.mess hasPrefix:@"SXlook:"]) {
        _myimageView.image = [UIImage imageNamed:@"yuedu"];
        NSString *str = [self.model.mess stringByReplacingOccurrencesOfString:@"SXlook:" withString:@"分享:"];
        NSArray *strArr = [str componentsSeparatedByString:@"网址"];
         _mess.text = [strArr firstObject];
    }else if ([self.model.mess hasPrefix:@"SXradio:"]) {
        _myimageView.image = [UIImage imageNamed:@"yinyue"];
        NSString *str = [self.model.mess stringByReplacingOccurrencesOfString:@"SXradio:" withString:@"分享:"];
        NSArray *strArr = [str componentsSeparatedByString:@"网址"];
         _mess.text = [strArr firstObject];
    }else{
        _myimageView.image = [UIImage imageNamed:@"xiaoxi"];
        _mess.text = self.model.mess;

    }
    
    _mess.numberOfLines = 0;
    
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
